package com.sctvcloud.dongqu.ui.adapter.holder;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;

import com.bigkoo.convenientbanner.holder.Holder;
import com.bumptech.glide.Glide;
import com.sctvcloud.dongqu.R;
import com.sctvcloud.dongqu.beans.HomeListItem;
import com.sctvcloud.dongqu.beans.NewsItem;
import com.sctvcloud.dongqu.ui.utils.GlideUtil;

/**
 * Created by panxd on 2016/9/5.
 */
public class BannerHolder implements Holder<NewsItem> {
    private ImageView imageView;
    public static final double TYPE_16_9 = 9 / 16;
    public static final double TYPE_21_9 = 9 / 21;
    private double type = TYPE_16_9;

    public BannerHolder(double type) {
        this.type = type;
    }

    public BannerHolder() {
    }
    @Override
    public View createView(Context context) {
        imageView = new ImageView(context);

        imageView.setAdjustViewBounds(true);
//        imageView.setLayoutParams(new ViewGroup.LayoutParams(width, height));
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

        int width = wm.getDefaultDisplay().getWidth();
        int height =(int) (width * type);
        imageView.setLayoutParams(new ViewGroup.LayoutParams(width, height));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        return imageView;
    }

    @Override
    public void UpdateUI(Context context, int position, NewsItem data) {
//        Glide.with(context).load(data.getNewsImage()).into(imageView);
//        GlideUtils.getGlideWithBannerDef(context,data.getNewsImage()).into(imageView);
//
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int width = wm.getDefaultDisplay().getWidth();
        int height = width * 16 / 9;
        String gitString = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1487250706899&di=086b0d8a070f4f65108cb14cb238c2ef&imgtype=0&src=http%3A%2F%2Fimg05.tooopen.com%2Fproducts%2F20141215%2FEC17D785-1E06-F2C9-8A4B-4CBE9D0C8B08.gif";
        String str = "ftp://test:asdfghjkl@120.76.100.2:21/upload/startpage/201702/22/20170222112136452.jpg";
//        Glide.with(context).load(data.getNewsImage()).override(width, height).into(imageView);
        GlideUtil.getGlid(context, data.getNewsImage()).centerCrop().placeholder(R.mipmap.icon_def_8_3).error(R.mipmap.icon_def_8_3).into(imageView);
//        GlideUtil.loadImgLarge169DefNotFit(context, data.getNewsImage(), imageView);
//                .into(
////        Glide.with(context).load(data.getNewsImage()).centerCrop().into(
//                new SimpleTarget<GlideDrawable>() {
//                    @Override
//                    public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
//                        imageView.setImageDrawable(resource);
//                    }
//                });
    }
}
